#include "structure_mot.hpp"

void created_chained_word(chained_word & c_w)
{
  c_w=NULL;
}

void add_word(chained_word & c_w,string line,int cpt)
{
  if(c_w==NULL)
    {
      c_w=new list_word;
      c_w->cpt=cpt;
      c_w->word=line;
      c_w->next=NULL;
    }
  else
    {
      list_word *aux,*l=c_w;

      aux=new list_word;
      aux->cpt=cpt;
      aux->word=line;
      aux->next=NULL;

      while(l->next!=NULL)
	l=l->next;

      l->next=aux;
    }
}

void print_chained(chained_word c_w)
{
  list_word * l=c_w;
  while(l!=NULL)
    {
      cout << l->cpt << " " << l->word << endl;
      l = l->next;
    }
}

string delete_word(chained_word & c_w)
{
  string r_mot="";

  if(c_w!=NULL)
    {
      list_word*tmp=c_w;
      r_mot=c_w->word;
      c_w=c_w->next;
      delete tmp;
    }

  return r_mot;
}

void delete_all(chained_word & c_w)
{
  while(c_w != NULL)
    delete_word(c_w);
}
